<?php
/**
 * ebiz front
 * 
 * HttpUtil
 *  
 * @author allen
 *  
 */
class HttpUtil 
{	
	
	public static function getGetValue ($field)
    {
    	if(isset($_GET[$field])){
    		return $_GET[$field];
    	}else{
    		return null;
    	}       
    }    
    
    public static function getPostValue ($field)
    {
    	if(isset($_POST[$field])){
    	   return $_POST[$field];
    	}else{
    		return null;
    	}
    }
    
    public static function getPostString ($field)
    {
        $value = isset($_POST[$field]) ? $_POST[$field] : null;
        if (isset($value)) {
            $value = trim($value);
            return $value;
        } else {
            return '';
        }
    }
    
    public static function getGetString ($field)
    {
//        $value = $_GET[$field];
        $value = isset($_GET[$field]) ? $_GET[$field] : null;
        if (isset($value)) {
            $value = trim($value);
            return $value;
        } else {
            return '';
        }
    }

    public static function getSessionString ($field, $node = "")
    {
        if (! empty($node)) {
            $value = $_SESSION[$node][$field];
        } else {
            $value = $_SESSION[$field];
        }
        if (isset($value)) {
            $value = trim($value);
            return $value;
        } else {
            return '';
        }
    }

    public static function getFilesString ($node, $field)
    {
        $value = $_FILES[$node][$field];
        if (isset($value)) {
            $value = trim($value);
            return $value;
        } else {
            return '';
        }
    }

    public static function getResultString ($result)
    {
        if (isset($result)) {
            if (is_array($result)) {
                foreach ($result as $key => $value) {
                    if (is_array($value)) {
                        foreach ($value as $k => $val) {
                            $value[$k] = stripslashes($val);
                            $result[$key] = $value;
                        }
                    } else {
                        $result[$key] = stripslashes($value);
                    }
                }
            } else {
                $result = stripslashes($result);
            }
            return $result;
        } else {
            return "";
        }
    }

    public static function getSelectDateString ($date)
    {
        if (isset($date)) {
            $date = explode(" - ", $date);
            foreach ($date as $key => $value) {
                $date = explode("/", $value);
                $result[$key] = $date[2] . "-" . $date[0] . "-" . $date[1];
            }
            return $result;
        } else {
            return "";
        }
    }

    public static function baseUrl(){
        $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
        return $baseUrl;
    }

    public static function getUrl($controller,$action){
        return Zend_View_Helper_Url::url(array('controller' => $controller , 'action' => $action));
    }

    public static function redirect404(){
    	require_once '../app/constants/ConfigConstants.php';
    	require_once '../app/views/error/404.php';
    	exit();
    }
    
    public static function renderError(){
        require_once '../app/views/error/404.php';
        exit();
    }  
    
    public static function renderEmptyProduct(){
        require_once '../app/views/error/EmptyProductView.php';
        exit();
    }  
    
    
}
